home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / sysdep2.c < prev    next >
C/C++ Source or Header  |  1995-09-16  |  45KB  |  1,841 lines

  1. #include "dos.h"
  2. #include "stdio.h"
  3. #include "ctdl.h"
  4. #include "string.h"
  5. #include "stdarg.h"
  6. #include "clib/dos_protos.h"
  7. #include "minrexx.h"
  8.  
  9. char *SysVers            = SYSDEP_NAME ;
  10.  
  11. char ARexx_Name[20];
  12. int  SystemPort          = 0;
  13. #define CITADEL_REQUIRED_STACK  8192L
  14. #ifdef CTDL_BACKGROUND
  15. long _stack              = CITADEL_REQUIRED_STACK;
  16. char *_procname          = "CTDL";
  17. long _priority           = 0;
  18. long _BackGroundIO       = 1;
  19. extern BPTR _Backstdout;
  20. #endif
  21.  
  22. int  iconify_window      = FALSE;   /* we are not iconified so printf uses
  23.                                        crash.sys for output in startup     */
  24.  
  25.  
  26.  
  27. /* CTDL EXTERNS */
  28. extern CONFIG cfg;
  29. extern char CallSysop;
  30. extern char ExitToMsdos;
  31. extern char whichIO;
  32. extern int exitValue;
  33. extern char onConsole; /* Where IO is ... */
  34. extern logBuffer logBuf;         /* Buffer for the pippuls       */
  35. extern aRoom  roomBuf;           /* Room buffer                  */
  36. extern char ForceNet,anyEcho;
  37.  
  38.  
  39. /* EXTERNS */
  40. void Save_Modem(char *,int ,char *);
  41. void Do_Stack_Check(void);
  42. void Dos_Error(long,char *);
  43. void ReActivate_Window(void);  /* allow window to be activated */
  44. int BufferModemFlush(void);
  45. int OpenSerialPorts(void);
  46. int CloseSerial(int final);
  47. void CloseSerialPorts(void);
  48. int Handle_Window_Msg(struct IntuiMessage *InMsg);
  49. int Handle_Little_Window_Msg(struct IntuiMessage *InMsg);
  50. int OpenLittleWindow(void);
  51. int CloseLittleWindow(void);
  52. int BufferConsoleFlush(void);
  53. int OpenConsoleStuff(void);
  54. int CloseConsoleStuff(void);
  55. struct Message *MyGetMsg(struct MsgPort *MyMsgPort);
  56. /*
  57. void  DebugIoRequest (char * string,struct IOExtSer *iorequest);
  58. void DebugIoStdReq(struct IOStdReq *Std);
  59. void Debug_Unit(   struct Unit *Un);
  60. void Debug_Device( struct Device *Dev);
  61. void Debug_Message(struct Message *Msg);
  62. void Debug_Device( struct Device *Dev);
  63. void Debug_space(void);
  64. */
  65. void timer(unsigned long t[2]);
  66. /* GLOBALS */
  67. extern char *VERSION;
  68. struct IntuitionBase *IntuitionBase = NULL;
  69. struct GfxBase       *GfxBase = NULL;
  70. /*struct Library       *ReqBase = NULL; */
  71. struct RastPort      *myScreensRPort = NULL;
  72. UWORD myScreensBLine = 6;
  73. char ConOpen = FALSE;
  74. char UsingREXX = FALSE;
  75. unsigned char conletter,serletter;
  76. short SerialOpen = 0,TimerOpen = 1,probval,oldfrom,serqueued = FALSE,conqueued = FALSE;
  77. struct IOStdReq    *consoleReadMsg   = NULL;
  78. struct MsgPort     *consoleReadPort  = NULL;
  79. struct IOStdReq    *consoleWriteMsg  = NULL;
  80. struct MsgPort     *consoleWritePort = NULL;
  81. struct IOExtSer    *mySerReadMsg     = NULL;
  82. struct MsgPort     *mySerReadPort    = NULL;
  83. struct IOExtSer    *mySerWriteMsg    = NULL;
  84. struct MsgPort     *mySerWritePort   = NULL;
  85. struct IOExtSer    *mySerStatusMsg   = NULL;
  86. struct MsgPort     *mySerStatusPort  = NULL;
  87. struct timerequest *myTimerMsg       = NULL;
  88. struct MsgPort     *myTimerPort      = NULL;
  89.  
  90. extern char logNetResults;
  91. extern FILE *netLog;
  92.  
  93. long char_out;                 /* total characters output */
  94. extern long char_in;           /* total characters input */
  95. extern long start_time;        /* total time for net session */
  96.  
  97. long total_time;               /* total time for all net sessions */
  98. long total_char_in;            /* totals for all time */
  99. long total_char_out;           /* totals for all time */
  100. int level;
  101.  
  102. #ifdef HANDLE_FALSE_CARRIER
  103. struct MsgPort     *SpecialMP;
  104. char SpecialMPName[32];
  105. struct MySpecialMessage
  106.   {
  107.   struct Message Message;
  108.   APTR FCAddress;
  109.  
  110.   }
  111. *SpecialMsg;
  112. #endif
  113. struct Screen *myScreen = NULL;
  114. struct NewScreen myNewScreen =
  115.   {
  116.   0,0,640,200,1,0,1,
  117.   HIRES, CUSTOMSCREEN, NULL, ">>>--> Citadel BBS <--<<<",
  118.   NULL, NULL
  119.  
  120.   };
  121.  
  122. char window_title[84];
  123. char NewScreenTitle[84];
  124. char lastuser[28];
  125. char NewWindowTitle[84];
  126. /*
  127. ** Screen/Window  Title format
  128. ** 1                   23                39
  129. ** [ Citadel Version | Date/Time stamp | System Status      ]
  130. ** 1                   25                              50
  131. ** [ Current User    | Current Room                   | Previous User     ]
  132. */
  133. struct Window *myWindow = NULL, *LittleWindow = NULL;
  134. struct NewWindow myNewWindow =
  135.   {
  136.   0,10,640,190,(UBYTE)-1,(UBYTE)-1,
  137.   CLOSEWINDOW,
  138.   SMART_REFRESH|NOCAREREFRESH|BORDERLESS|RMBTRAP|
  139.   WINDOWCLOSE|WINDOWSIZING|WINDOWDRAG|WINDOWDEPTH,
  140.   NULL, NULL, NULL, NULL, NULL,
  141.   200,40, 1000,1000, CUSTOMSCREEN
  142.  
  143.   };
  144. long timerworks = FALSE;
  145. long timercount = 0;
  146. char internalserial;
  147. #ifdef HANDLE_FALSE_CARRIER
  148. char FalseCarrier = 0;
  149. #endif
  150. UBYTE OpenSerFlags;
  151. struct Task    *MyTask    = NULL;
  152. struct Process *MyProcess = NULL;
  153. struct CommandLineInterface *CLI;
  154. ULONG TStackSz, PStackSz, DefStackSz;
  155. char WBWindow,CLINum;
  156. #define TALKTOREXX
  157. #ifdef TALKTOREXX
  158. /*
  159. *   We need our include file.
  160. */
  161. #include "minrexx.h"
  162. /*
  163. *   These are the REXX functions defined at the bottom of the file.
  164. */
  165. int disp(struct RexxMsg *msg, struct rexxCommandList *dat, char *p);
  166. void rexxsetchat(struct RexxMsg *msg, char *p);
  167. void rexxsetecho(struct RexxMsg *msg, char *p);
  168. void rexxsetnud(struct RexxMsg *msg, char *p);
  169. void rexxexit(struct RexxMsg *msg, char *p);
  170. void rexxversion(struct RexxMsg *msg, char *p);
  171. void rexxserialenable(struct RexxMsg *msg, char *p);
  172. void rexxopenconsole(struct RexxMsg *msg, char *p);
  173. void rexxiconify(struct RexxMsg *msg, char *p);
  174. #ifdef HANDLE_FALSE_CARRIER
  175. void rexxcarrier(struct RexxMsg *msg, char *p);
  176. #endif
  177. /*
  178. *   Here is our command association list.  Note that in this case,
  179. *   we are setting the userdata field to be a function to call.
  180. *   Dispatch will still take place through moodisp(), so common head
  181. *   and tail stuff can go there.
  182. *
  183. *   Commands are all lower case, so we match either upper or lower.
  184. *   (This is a requirement of minrexx.)
  185. */
  186. struct rexxCommandList rcl[] =
  187.   {
  188.     { "setchat",          (APTR)rexxsetchat },
  189.     { "setecho",          (APTR)rexxsetecho },
  190.     { "setnouserdisable", (APTR)rexxsetnud },
  191.     { "exit",             (APTR)rexxexit },
  192.     { "version",          (APTR)rexxversion },
  193.     { "serialenable",     (APTR)rexxserialenable },
  194.     { "openconsole",      (APTR)rexxopenconsole },
  195.     { "iconify",          (APTR)rexxiconify },
  196.   #ifdef HANDLE_FALSE_CARRIER
  197.     { "carrier",          (APTR)rexxcarrier },
  198.   #endif
  199.     { NULL, NULL } };
  200. #endif
  201.  
  202. unsigned long Set_Timer(unsigned long oldtime ) /* return the delta from oldtime in microsecs*/
  203.   {
  204.   unsigned long clock[2];
  205.   timer(clock);      /* get old time */
  206.   return ( clock[0] - oldtime );
  207.   }
  208.  
  209. static char lognet[80];
  210. static char date2[6], date1[6];
  211. static void Write_Total_Data(void);
  212. void Read_Total_Data(void);
  213.  
  214. void Read_Total_Data()
  215.   {
  216.   char *mon;
  217.   FILE *ip;
  218.   int lyr, ldum;
  219.   if( cfg.Audit == 0 )return;
  220.   makeAuditName(lognet, "Network_stats.sys");
  221.   if( (ip = fopen(lognet, "r")) != NULL )
  222.     {
  223.     fread(&date1,         6, 1, ip);
  224.     fread(&total_time,    4, 1, ip);
  225.     fread(&total_char_in, 4, 1, ip);
  226.     fread(&total_char_out,4, 1, ip);
  227.     fclose(ip);
  228.     getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  229.     sprintf(date2,"%3s%2d",mon,lyr);      /* monthYear */
  230.     if( strcmp(date1,date2) != 0 )
  231.       {
  232.       /* reset, new month  */
  233.       getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  234.       sprintf(date1,"%3s%2d",mon,lyr);      /* monthYear */
  235.       total_time    = 0;
  236.       total_char_in = 0;
  237.       total_char_out= 0;
  238.       Write_Total_Data();
  239.       }
  240.     }
  241.   else   /* no file, create it */
  242.     {
  243.     getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  244.     sprintf(date1,"%3s%2d",mon,lyr);      /* monthYear */
  245.     total_time    = 0;
  246.     total_char_in  = 0;   /* new file */
  247.     total_char_out = 0;
  248.     Write_Total_Data();
  249.     }
  250.   }
  251.  
  252. static void Write_Total_Data()
  253.   {
  254.   FILE *ip;
  255.   if( cfg.Audit == 0 )return;
  256.   makeAuditName(lognet, "Network_stats.sys");
  257.   if( (ip = fopen(lognet, "w")) != NULL )
  258.     {
  259.     fwrite(date1,          6, 1, ip);
  260.     fwrite(&total_time,    4, 1, ip);
  261.     fwrite(&total_char_in, 4, 1, ip);
  262.     fwrite(&total_char_out,4, 1, ip);
  263.     fclose(ip);
  264.     }
  265.   }
  266.  
  267. void Compute_Data(char *name)
  268.   {
  269.   int lyr,ldum;
  270.   char *mon;
  271.   FILE *ip;
  272.   long cps;           /* computed data rate */
  273.   long work_time;
  274.   work_time = Set_Timer(start_time);
  275.   if( logNetResults )
  276.     {
  277.     cps = ( char_in + char_out ) / work_time;
  278.     splitF(netLog," Characters Input:%ld Characters Output:%ld  %ld cps\n", char_in, char_out, cps);
  279.     if( cfg.Audit  )
  280.       {
  281.       makeAuditName(lognet,"Network_Istats.sys");
  282.       if( (ip = fopen(lognet, "a")) != NULL)
  283.         {
  284.         getCdate(&lyr,&mon,&ldum,&ldum,&ldum);
  285.         sprintf(date2,"%3s%2d",mon,lyr);      /* monthYear */
  286.         fprintf(ip,"%s %20s %10ld %10ld %10ld\n",date2,name, char_in, char_out, work_time);
  287.         fclose(ip);
  288.         };
  289.  
  290.       };
  291.     }
  292.   Read_Total_Data();
  293.   total_time     += work_time;
  294.   total_char_in  += char_in;
  295.   total_char_out += char_out;
  296.   Write_Total_Data();
  297.   }
  298.  
  299. int nodie(void)
  300.   {
  301.   Do_Stack_Check();
  302.   return(0);
  303.  
  304.   }
  305. int openStuff(void)
  306.   {
  307.   int error;
  308.   extern char anyEcho;
  309.   extern char BpsSet;
  310.   extern long byteRate;
  311.   extern long BaudTable[];
  312.   #ifdef TALKTOREXX
  313.   /*
  314.   *   If we are talking to REXX, we need this additional local.
  315.   */
  316.   long rexxbit ;
  317.   #endif
  318.   Do_Stack_Check();
  319.   probval   = 99;
  320.   termWidth = 40;
  321.   total_char_in = total_char_out = 0;
  322.   IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",33);
  323.   if (!IntuitionBase)
  324.     {
  325.     Dos_Error(1,"Open intuition.Library failed");
  326.     probval = 1;
  327.     goto thisend;
  328.  
  329.     }
  330.   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
  331.   if (!GfxBase)
  332.     {
  333.     Dos_Error(2,"Open graphics.library failed");
  334.     probval = 2;
  335.     goto thisend;
  336.  
  337.     }
  338. /*
  339.   ReqBase = (struct Library *)OpenLibrary("req.library",0);
  340.   if (!ReqBase)
  341.     {
  342.     Dos_Error(2,"Open req.library failed");
  343.     probval = 2;
  344.     goto thisend;
  345.  
  346.     }
  347. */
  348.   MyTask     = FindTask(0L);
  349.   MyProcess  = (struct Process *)MyTask;
  350.   CLI = (struct CommandLineInterface *)(MyProcess->pr_CLI << 2);
  351.   if( CLI )
  352.     {
  353.     DefStackSz = CLI->cli_DefaultStack << 2;
  354.     }
  355.   else
  356.     {
  357.     DefStackSz = MyProcess->pr_StackSize;
  358.     };
  359.   if( DefStackSz < CITADEL_REQUIRED_STACK )
  360.     {
  361.     printf("Current Default Stack = %ld\n",DefStackSz);
  362.     printf("This program needs a stack greater than %ld\n",CITADEL_REQUIRED_STACK);
  363.     Dos_Error(3,"Insufficient Stack Space allocated");
  364.     probval = 3;
  365.     goto thisend;
  366.  
  367.     }
  368.   WBWindow = cfg.DepData.ScreenDepth;
  369.   error    = OpenConsoleStuff();
  370.   if (error < 0)
  371.     {
  372.     Dos_Error(error,"Console Open Error");
  373.     probval = 11;
  374.     goto thisend;
  375.  
  376.     }
  377.   #ifdef CTDL_BACKGROUND
  378.   Close(_Backstdout);
  379.   _Backstdout = 0;
  380.   #endif
  381.   anyEcho = cfg.DepData.StartUpEcho;
  382.   onbreak(nodie);
  383.   error = OpenSerialPorts();
  384.   if (error == ERROR)
  385.     {
  386.     probval = 25;
  387.     Dos_Error(probval,"Open Serial Port Failed");
  388.     goto thisend;
  389.  
  390.     }
  391.   SerialOpen = FALSE;
  392.   myTimerPort = CreatePort(0,0);
  393.   if (!myTimerPort)
  394.     {
  395.     probval = 31;
  396.     Dos_Error(probval,"Create Port Failed");
  397.     goto thisend;
  398.  
  399.     }
  400.   myTimerMsg = (struct timerequest *)CreateExtIO(myTimerPort, sizeof(struct timerequest));
  401.   if (!myTimerMsg)
  402.     {
  403.     probval = 32;
  404.     Dos_Error(probval,"Create I/O Requests Failed");
  405.     goto thisend;
  406.  
  407.     }
  408.   TimerOpen = OpenDevice(TIMERNAME,UNIT_VBLANK,(struct IORequest *)myTimerMsg,0);
  409.   if (TimerOpen != 0)
  410.     {
  411.     probval = 33;
  412.     Dos_Error(probval,"Open timer.device failed");
  413.     goto thisend;
  414.  
  415.     }
  416.   timerworks = TRUE;
  417.   #ifdef TALKTOREXX
  418.   /*
  419.   *   For rexx, we open up a Rexx port, and send out the first command,
  420.   *   if there was one.  We send it out asynchronously; no reason not to.
  421.   */
  422.   sprintf(ARexx_Name,"Citadel_68K");
  423.   if( FindPort(ARexx_Name) != NULL )
  424.     {
  425.     sprintf(ARexx_Name,"Citadel_68K_%d",CLINum);
  426.     if( FindPort(ARexx_Name) != NULL )
  427.       {
  428.       printf("Unique ARexx_Port Name Failure:%s\n",ARexx_Name);
  429.       };
  430.     };
  431.   rexxbit = upRexxPort(ARexx_Name, rcl, "rexx", &disp) ;
  432.   if (rexxbit != 0)
  433.     {
  434.     UsingREXX = TRUE;
  435.     printf("Rexx Port Name [Citadel_68K]\n ");
  436.  
  437.     }
  438.   #endif
  439.   #ifdef HANDLE_FALSE_CARRIER
  440.   sPrintf(SpecialMPName,"Citadel68K_Spcl_%d",CLINum);
  441.   SpecialMP = CreatePort(SpecialMPName,0);
  442.   if (SpecialMP)
  443.     {
  444.     printf("Special Port Name [%s]\n ",SpecialMPName);
  445.     #ifdef AUTO_EXEC_FALSECARRIER
  446.     sPrintf(NewWindowTitle,"run jays:falsecarrier/fc %d",CLINum);
  447.     Execute(NewWindowTitle,0L,0L);
  448.     WaitPort(SpecialMP);
  449.     SpecialMsg = (struct MySpecialMsg *)GetMsg(SpecialMP);
  450.     if (SpecialMsg)
  451.       {
  452.       SpecialMsg->FCAddress = &FalseCarrier;
  453.       ReplyMsg((struct Message *)SpecialMsg);
  454.  
  455.       }
  456.     #endif
  457.  
  458.     }
  459.   #endif
  460.   if (!BpsSet)  byteRate = (BaudTable[cfg.sysBaud] / 10L);
  461.   thisend:
  462.   if (probval != 99)
  463.     {
  464.     fprintf(stderr, "Startup Error Code %d\n",probval);
  465.     }
  466.   else       printf("System Initialized ok\n");
  467.   strcpy(lastuser," ***None*** ");
  468.   return (probval);
  469.  
  470.   }
  471. void closeStuff(int oldprobval)
  472.   {
  473.   Do_Stack_Check();
  474.   #ifdef TALKTOREXX
  475.   /*
  476.   *   With Rexx, we need to bring the port down.  You might make this
  477.   *   part of exit() for programs that have multiple paths to exit.
  478.   */
  479.   if (UsingREXX) dnRexxPort() ;
  480.   #endif
  481.   #if HANDLE_FALSE_CARRIER
  482.   if (SpecialMP)  DeletePort(SpecialMP);
  483.   #endif
  484.   timerworks = FALSE;
  485.   if ((probval > 34) && !TimerOpen)  CloseDevice((struct IORequest *)myTimerMsg);
  486.   if ((probval > 33) && myTimerMsg)  DeleteExtIO((struct IORequest *)myTimerMsg);
  487.   if ((probval > 32) && myTimerPort) DeletePort(myTimerPort);
  488.   if ((probval > 25) && SerialOpen)  CloseSerial(TRUE);
  489.   if (probval > 25)  CloseSerialPorts();
  490.   if (probval > 11)  CloseConsoleStuff();
  491.   if (LittleWindow)  CloseWindow(LittleWindow);
  492. /*  if (ReqBase)  CloseLibrary(ReqBase); */
  493.   if (GfxBase)  CloseLibrary((struct Library *)GfxBase);
  494.   if (IntuitionBase)  CloseLibrary((struct Library *)IntuitionBase);
  495.  
  496.   }
  497.  
  498.  
  499. #define FULL_BUFFER ( 1279 )
  500. int DoBufferModem,BufferModemCount;
  501. UBYTE ModemBuffer[FULL_BUFFER+1];
  502. int DoBufferConsole,BufferConsoleCount;
  503. char ConsoleBuffer[128];
  504.  
  505. void BufferingOn(void)
  506.   {
  507.   Do_Stack_Check();
  508.   DoBufferModem = TRUE;
  509.   DoBufferConsole = TRUE;
  510.  
  511.   }
  512. void BufferingOff(void)
  513.   {
  514.   Do_Stack_Check();
  515.   DoBufferModem = FALSE;
  516.   BufferModemFlush();
  517.   DoBufferConsole = FALSE;
  518.   BufferConsoleFlush();
  519.  
  520.   }
  521. int BufferModemFlush(void)
  522.   {
  523.   Do_Stack_Check();
  524.   if (SerialOpen && BufferModemCount && gotCarrier())
  525.     {
  526.     mySerWriteMsg->IOSer.io_Data = (APTR)ModemBuffer;
  527.     mySerWriteMsg->IOSer.io_Length = BufferModemCount;
  528.     mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  529.     char_out += BufferModemCount;
  530.     DoIO((       struct IORequest *)mySerWriteMsg);
  531.     }
  532.   BufferModemCount = 0;
  533.   return(TRUE);
  534.  
  535.   }
  536. char static_send;
  537. char outMod(int character)
  538.   {
  539.   Do_Stack_Check();
  540.   if(DoBufferModem)
  541.     {
  542.     ModemBuffer[BufferModemCount++] = character;
  543.     if(BufferModemCount > FULL_BUFFER )
  544.       {
  545.       BufferModemFlush();
  546.  
  547.       }
  548.  
  549.     }
  550.   else
  551.     {
  552.     if (SerialOpen)
  553.       {
  554.       static_send = character;
  555.       mySerWriteMsg->IOSer.io_Data = (APTR)&static_send;
  556.       mySerWriteMsg->IOSer.io_Length = 1;
  557.       mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  558.       DoIO(       (struct IORequest *)mySerWriteMsg);
  559.       char_out++;
  560.       }
  561.  
  562.     }
  563.   return(TRUE);
  564.  
  565.   }
  566. int QueueSerRead(int where)
  567.   {
  568.   Do_Stack_Check();
  569.   if (!serqueued && SerialOpen)
  570.     {
  571.     mySerReadMsg->IOSer.io_Command = CMD_READ;
  572.     mySerReadMsg->IOSer.io_Data = (APTR)&serletter;
  573.     mySerReadMsg->IOSer.io_Length = 1;
  574.     char_in++;
  575.     SendIO((struct IORequest *)mySerReadMsg);
  576.     serqueued = TRUE;
  577.  
  578.     }
  579.   return(TRUE);
  580.  
  581.   }
  582. int UnQueueSerRead(void)
  583.   {
  584.   Do_Stack_Check();
  585.   if (serqueued && SerialOpen)
  586.     {
  587.     AbortIO((struct IORequest *)mySerReadMsg);
  588.     WaitPort(mySerReadPort);
  589.     MyGetMsg(mySerReadPort);
  590.     serqueued = FALSE;
  591.  
  592.     }
  593.   return(TRUE);
  594.  
  595.   }
  596. int serPutStr(struct IOExtSer *mess,char *str)
  597.   {
  598.   Do_Stack_Check();
  599.   if (SerialOpen)
  600.     {
  601.     mySerWriteMsg->IOSer.io_Command = CMD_WRITE;
  602.     mySerWriteMsg->IOSer.io_Data = (APTR)str;
  603.     mySerWriteMsg->IOSer.io_Length = strlen(str);
  604.     char_out += mySerWriteMsg->IOSer.io_Length;
  605.     DoIO(       (struct IORequest *)mySerWriteMsg);
  606.  
  607.  
  608.     }
  609.   return(TRUE);
  610.  
  611.   }
  612. #ifdef NEEDED
  613. /*
  614. * This code provided by Gabriel Broner, a s/w engineer at CPT Corp.
  615. *
  616. * First argument is the mask, second argument is a non-ambiguous string to
  617. * check against.
  618. */
  619. testsamefn (s1, s2)
  620. char *s1, *s2;
  621.   {
  622.   Do_Stack_Check();
  623.   if (*s1 == 0)
  624.     {
  625.     if (*(s1 - 1) == '*' || *s2 == 0)
  626.     return TRUE;
  627.     return FALSE;
  628.  
  629.     }
  630.   if (*s2 == 0)
  631.   return FALSE;
  632.   if (*s1 == *s2 || *s1 == '?')
  633.   return testsamefn(s1 + 1, s2 + 1);
  634.   if (*s1 == '*')
  635.   return (testsamefn(s1+1, s2) || testsamefn(s1, s2+1));
  636.   return FALSE;
  637.  
  638.   }
  639. #endif
  640. int OpenSerialPorts(void)
  641.   {
  642.   int erred;
  643.   erred = 0;
  644.   Do_Stack_Check();
  645.   mySerReadPort = CreatePort(0,0);
  646.   if (!mySerReadPort)
  647.     {
  648.     erred = 1;
  649.     Dos_Error(erred,"Create Read Port Failed");
  650.  
  651.     }
  652.   if (!erred)
  653.     {
  654.     mySerReadMsg = (struct IOExtSer *)CreateExtIO(mySerReadPort, sizeof(struct IOExtSer));
  655.     if (!mySerReadMsg)
  656.       {
  657.       erred = 2;
  658.       Dos_Error(erred,"Create Read ExtIO Failed");
  659.  
  660.       }
  661.  
  662.     }
  663.   if (!erred)
  664.     {
  665.     mySerWritePort = CreatePort(0,0);
  666.     if (mySerWritePort == NULL)
  667.       {
  668.       erred = 3;
  669.       Dos_Error(erred,"Create Write Port Failed");
  670.  
  671.       }
  672.  
  673.     }
  674.   if (!erred)
  675.     {
  676.     mySerWriteMsg = (struct IOExtSer *)CreateExtIO(mySerWritePort, sizeof(struct IOExtSer));
  677.     if (mySerWriteMsg == NULL)
  678.       {
  679.       erred = 4;
  680.       Dos_Error(erred,"Create Write ExtIO Failed");
  681.  
  682.       }
  683.  
  684.     }
  685.   if (!erred)
  686.     {
  687.     mySerStatusPort = CreatePort(0,0);
  688.     if (mySerStatusPort == NULL)
  689.       {
  690.       erred = 5;
  691.       Dos_Error(erred,"Create Status Port Failed");
  692.  
  693.       }
  694.  
  695.     }
  696.   if (!erred)
  697.     {
  698.     mySerStatusMsg = (struct IOExtSer *)CreateExtIO(mySerStatusPort,
  699.     sizeof(struct IOExtSer));
  700.     if (mySerStatusMsg == NULL)
  701.       {
  702.       erred = 6;
  703.       Dos_Error(erred,"Create Status ExtIO Failed");
  704.  
  705.       }
  706.  
  707.     }
  708.   if (erred)
  709.     {
  710.     CloseSerialPorts();
  711.  
  712.     }
  713.   return((erred) ? 0 : 1);
  714.  
  715.   }
  716. int OpenSerial(int starting)
  717.   {
  718.   int serror;
  719.   extern long byteRate;
  720.   ULONG devnum;
  721.   char devname[32];
  722.   Do_Stack_Check();
  723.   if (!SerialOpen)
  724.     {
  725.     strncpy(devname,cfg.DepData.DevName,31);
  726.     devname[31] = '\0';
  727.     devnum = cfg.DepData.UnitNumber;
  728.     if (!strcmp(devname,"serial.device") && devnum != 0)
  729.     internalserial = TRUE;
  730.     else  internalserial = FALSE;
  731.     OpenSerFlags = SERF_XDISABLED | SERF_SHARED|SERF_RAD_BOOGIE;
  732.     if (cfg.DepData.Clock & SER_7WIRE)
  733.       {
  734.       OpenSerFlags |= SERF_7WIRE;
  735.       };
  736.     mySerReadMsg->io_SerFlags = OpenSerFlags;
  737.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerReadMsg,0);
  738.     if (serror != 0)
  739.       {
  740.       Dos_Error(serror,"Open Device for serial port failed");
  741.       return(ERROR);
  742.       };
  743.     mySerWriteMsg->io_SerFlags = OpenSerFlags;
  744.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerWriteMsg,0);
  745.     if (serror != 0)
  746.       {
  747.       Dos_Error(serror,"Open Device for serial port failed");
  748.       CloseDevice((struct IORequest *)mySerReadMsg);
  749.       return(ERROR);
  750.  
  751.       }
  752.     mySerStatusMsg->io_SerFlags = OpenSerFlags;
  753.     serror = OpenDevice(devname,devnum,(struct IORequest *)mySerStatusMsg,0);
  754.     if (serror != 0)
  755.       {
  756.       Dos_Error(serror,"Open Device for serial port failed");
  757.       CloseDevice((struct IORequest *)mySerReadMsg);
  758.       CloseDevice((struct IORequest *)mySerWriteMsg);
  759.       return(ERROR);
  760.  
  761.       }
  762.     mySerStatusMsg->io_RBufLen  = mySerReadMsg->io_RBufLen  = mySerWriteMsg->io_RBufLen = 2048;
  763.     mySerStatusMsg->io_ReadLen  = mySerReadMsg->io_ReadLen  = mySerWriteMsg->io_ReadLen = 8;
  764.     mySerStatusMsg->io_WriteLen = mySerReadMsg->io_WriteLen = mySerWriteMsg->io_WriteLen = 8;
  765.     mySerStatusMsg->io_StopBits = mySerReadMsg->io_StopBits = mySerWriteMsg->io_StopBits = 1;
  766.     mySerStatusMsg->io_TermArray.TermArray0 = mySerReadMsg->io_TermArray.TermArray0 = mySerWriteMsg->io_TermArray.TermArray0 = NULL;
  767.     mySerStatusMsg->io_TermArray.TermArray1 = mySerReadMsg->io_TermArray.TermArray1 = mySerWriteMsg->io_TermArray.TermArray1 = NULL;
  768.     mySerStatusMsg->IOSer.io_Command = SDCMD_SETPARAMS;
  769.     DoIO(       (struct IORequest *)mySerStatusMsg);
  770.     SerialOpen = TRUE;
  771.     if (byteRate != 0)
  772.       CitadelBaudRate(byteRate, "OpenSerial:byteRate");
  773.     else CitadelBaudRate(cfg.sysBaud,"OpenSerial:sysBaud");
  774.     QueueSerRead(1);
  775.  
  776.     }
  777.   return(TRUE);
  778.  
  779.   }
  780. int CloseSerial(int final)
  781.   {
  782.   Do_Stack_Check();
  783.   if (SerialOpen)
  784.     {
  785.     UnQueueSerRead();
  786.     CloseDevice((struct IORequest *)mySerStatusMsg);
  787.     CloseDevice((struct IORequest *)mySerWriteMsg);
  788.     CloseDevice((struct IORequest *)mySerReadMsg);
  789.     SerialOpen = FALSE;
  790.     return(FALSE);
  791.  
  792.     }
  793.   return(TRUE);
  794.  
  795.   }
  796. void CloseSerialPorts(void)
  797.   {
  798.   Do_Stack_Check();
  799.   if (mySerStatusMsg)
  800.     {
  801.     DeleteExtIO((struct IORequest *)mySerStatusMsg);
  802.     mySerStatusMsg = NULL;
  803.  
  804.     }
  805.   if (mySerWriteMsg)
  806.     {
  807.     DeleteExtIO((struct IORequest *)mySerWriteMsg);
  808.     mySerWriteMsg = NULL;
  809.  
  810.     }
  811.   if (mySerReadMsg)
  812.     {
  813.     DeleteExtIO((struct IORequest *)mySerReadMsg);
  814.     mySerReadMsg = NULL;
  815.  
  816.     }
  817.   if (mySerStatusPort)
  818.     {
  819.     DeletePort(mySerStatusPort);
  820.     mySerStatusPort = NULL;
  821.  
  822.     }
  823.   if (mySerWritePort)
  824.     {
  825.     DeletePort(mySerWritePort);
  826.     mySerWritePort = NULL;
  827.  
  828.     }
  829.   if (mySerReadPort)
  830.     {
  831.     DeletePort(mySerReadPort);
  832.     mySerReadPort = NULL;
  833.  
  834.     }
  835.  
  836.   }
  837. char time_in[30];
  838. char sstatus[30];
  839. int timeupdatecount,old_user;
  840. int old_shr, old_smn;
  841. void ScrTimeUpdate(int shr, int smn)
  842.   {
  843.   Do_Stack_Check();
  844.   timeupdatecount = 0;
  845.   if (!ConOpen) return;
  846.   if( old_shr == shr && old_smn == smn )return;
  847.   old_shr = shr;
  848.   old_smn = smn;
  849.   if (myScreensRPort)
  850.     {
  851.     sPrintf(NewScreenTitle,"Citadel 68K V%s.%s| %2d:%02d %7s | %-30s"
  852.     ,VERSION,SysVers,shr,smn,formDate(),sstatus);
  853.     SetWindowTitles(myWindow,window_title,NewScreenTitle);
  854.     }
  855.  
  856.   }
  857. void ScrNewUser(void)
  858.   {
  859.   char temp_title[84],*smo;
  860.   int syr,sdy,shr,smn;
  861.   Do_Stack_Check();
  862.   getCdate(&syr,&smo,&sdy,&shr,&smn);
  863.   if (!ConOpen || !myWindow) return;
  864.   if (!old_user && logBuf.lbname[0])
  865.     {
  866.     sPrintf(time_in,"In: %2d:%02d                    ",shr,smn);
  867.     old_user = 1;
  868.  
  869.     }
  870.   if (!logBuf.lbname[0] && old_user)
  871.     {
  872.     strcpy(time_in," *** None ***               ");
  873.     old_user = 0;
  874.  
  875.     }
  876.   sPrintf(temp_title,"User:%-19s|Room:%-19s|%c%c%c%s|Last:%s"
  877.   ,logBuf.lbname,  roomBuf.rbname,
  878.   (cfg.BoolFlags.noChat) ?  ' ' : 'C',
  879.   (cfg.BoolFlags.debug)  ?  'D' : ' ',
  880.   (anyEcho)              ?  'E' : ' ',
  881.   (CallSysop)            ? "^T" :((ForceNet) ? "^A" : "  "),
  882.   lastuser);
  883.   strncpy(window_title,temp_title,83);
  884.   old_smn = -1;
  885.   SpecialMessage(time_in);
  886.   }
  887. char oldmsg[30];
  888. void SpecialMessage(char *message)
  889.   {
  890.   short j;
  891.   char realmsg[30];
  892.   char *smo;
  893.   int syr,sdy,shr,smn;
  894.   Do_Stack_Check();
  895.   timeupdatecount = 0;
  896.   if (!ConOpen) return;
  897.   if (myScreensRPort)
  898.     {
  899.     j = strlen(message);
  900.     memset(realmsg,'\0',30);
  901.     if( j > 29)j = 29;
  902.     strncpy(realmsg,message,j);
  903.     realmsg[j] = '\0';
  904.     if( strcmp(oldmsg,realmsg) != 0 )      /* do not update unless change*/
  905.       {
  906.       sprintf(sstatus,"%-30s",realmsg);
  907.       getCdate(&syr,&smo,&sdy,&shr,&smn);
  908.       ScrTimeUpdate(shr, smn);
  909.       strcpy(oldmsg,realmsg);
  910.       };
  911.     }
  912.  
  913.   }
  914. /************************************************************************/
  915. /*   pause() busy-waits N/100 seconds            */
  916. /************************************************************************/
  917. void pause(int i)
  918.   {
  919.   ULONG secs, micros;
  920.   Do_Stack_Check();
  921.   if( myTimerMsg == NULL)return;
  922.   secs = i / 100;
  923.   micros = (i - (secs * 100)) * 10000;
  924.   if (!secs && !micros)  micros = 10000;
  925.   if (micros < 0 || micros > 999999)
  926.     {
  927.     printf("[pause(%d) micros = %ld]",i,micros);
  928.     micros = 10000;
  929.  
  930.     }
  931.   myTimerMsg->tr_node.io_Command = TR_ADDREQUEST;
  932.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  933.   myTimerMsg->tr_time.tv_secs = secs;
  934.   myTimerMsg->tr_time.tv_micro = micros;
  935.   DoIO((struct IORequest *)myTimerMsg);
  936.  
  937.   }
  938. void MilliSecPause(int x)
  939.   {  /* really a 100 microsecond delay per x */
  940.   long micros;
  941.   Do_Stack_Check();
  942.   if( myTimerMsg == NULL)return;
  943.   if( x < 1 || x > 1000)x = 1000;  /* out of range, give max */
  944.   micros = x * 100;                /* time in 100 microsecond units */
  945.   myTimerMsg->tr_node.io_Command = TR_ADDREQUEST;
  946.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  947.   myTimerMsg->tr_time.tv_secs  = 0;
  948.   myTimerMsg->tr_time.tv_micro = micros;
  949.   DoIO((struct IORequest *)myTimerMsg);
  950.  
  951.   }
  952. void timer(unsigned long t[2])
  953.   {
  954.   Do_Stack_Check();
  955.   if( myTimerMsg == NULL)return;
  956.   myTimerMsg->tr_node.io_Message.mn_ReplyPort = myTimerPort;
  957.   myTimerMsg->tr_node.io_Command = TR_GETSYSTIME;
  958.   DoIO((struct IORequest *)myTimerMsg);
  959.   t[0] = myTimerMsg->tr_time.tv_secs;
  960.   t[1] = myTimerMsg->tr_time.tv_micro;
  961.  
  962.   }
  963. #ifdef TALKTOREXX
  964. /*
  965. *   Now we get into the actual code necessary for our REXX port; functions
  966. *   that do the real work.  Note that this program was not structured
  967. *   particularly nicely for Rexx; I had to write each of these functions.
  968. *   Many programs have these subroutines already in place; they are called
  969. *   as part of the event loop.  This progam, however, just has one big
  970. *   switch statement with different actions . . .
  971. *
  972. *   First, our locals.
  973. */
  974. int args[4] ;              /* what args did we see to this function? */
  975. int parsed ;               /* was argument parsing successful? */
  976. int userreplied ;          /* has the current message been replied to yet? */
  977. /*
  978. *   This function takes a pointer to a pointer to a string, grabs the
  979. *   next number, returns it, and advances the pointer to the string to
  980. *   point after the number.
  981. */
  982. int getnm(char **where)
  983.   {
  984.   register char *p = *where ;
  985.   register int val = 0 ;
  986.   int gotone = 0 ;
  987.   Do_Stack_Check();
  988.   while (*p <= ' ' && *p)  p++ ;
  989.   while ('0' <= *p && *p <= '9')
  990.     {
  991.     gotone = 1 ;
  992.     val = 10 * val + *p++ - '0' ;
  993.  
  994.     }
  995.   if (gotone == 0)  parsed = 0 ;
  996.   *where = p ;
  997.   return(val) ;
  998.  
  999.   }
  1000. /*
  1001. *   This function trys to find `n' numeric arguments in the command
  1002. *   string, and stuffs them into the args array.
  1003. */
  1004. void parseargs(char *p, int n)
  1005.   {
  1006.   register int i ;
  1007.   Do_Stack_Check();
  1008.   while (*p > ' ' && *p)  p++ ;
  1009.   for (i=0; i<n; i++)  args[i] = getnm(&p) ;
  1010.  
  1011.   }
  1012. /*
  1013. *   This is our main dispatch function.  We check to make sure a Window
  1014. *   currently exists.  Then, we store away the `current color' and change
  1015. *   it to Rexx's current color, call our handler function, and then restore
  1016. *   the color.  If our handler replied, we return a 1 to indicate that.
  1017. *   If the parse and everything else was successful, we return a 0.
  1018. *   Otherwise, we return a failure of 20 to indicate that the arguments
  1019. *   were messed up.
  1020. */
  1021. int disp(struct RexxMsg *msg, struct rexxCommandList *dat, char *p)
  1022.   {
  1023.   parsed = 1 ;
  1024.   Do_Stack_Check();
  1025.   userreplied = 0 ;
  1026.   ((int (*)())(dat->userdata))(msg, p) ;
  1027.   if (! parsed) replyRexxCmd(msg, (long)parsed, 0L, NULL) ;
  1028.   return TRUE;
  1029.  
  1030.   }
  1031. #endif
  1032. #ifdef TALKTOREXX
  1033. char dorexxexit = FALSE;
  1034. #endif
  1035. int Amiga_System_Input(void)
  1036.   {
  1037.   struct IntuiMessage *InMsg;
  1038.   Do_Stack_Check();
  1039.   #ifdef TALKTOREXX
  1040.   /*
  1041.   *   Handle any Rexx messages.
  1042.   */
  1043.   if (UsingREXX)  dispRexxPort() ;
  1044.   #endif
  1045.   #ifdef HANDLE_FALSE_CARRIER
  1046.   if (SpecialMP)
  1047.     {
  1048.     SpecialMsg = (struct MySpecialMsg *)GetMsg(SpecialMP);
  1049.     if (SpecialMsg)
  1050.       {
  1051.       SpecialMsg->FCAddress = &FalseCarrier;
  1052.       ReplyMsg(SpecialMsg);
  1053.  
  1054.       }
  1055.  
  1056.     }
  1057.   #endif
  1058.   if (ConOpen)
  1059.     {
  1060.     InMsg = (struct IntuiMessage *)GetMsg(myWindow->UserPort);
  1061.     if (InMsg != NULL) Handle_Window_Msg(InMsg);
  1062.  
  1063.     }
  1064.   if (LittleWindow != NULL)
  1065.     {
  1066.     InMsg = (struct IntuiMessage *)GetMsg(LittleWindow->UserPort);
  1067.     if (InMsg != NULL) Handle_Little_Window_Msg(InMsg);
  1068.  
  1069.     }
  1070.   return(0);
  1071.  
  1072.   }
  1073. #ifdef TALKTOREXX
  1074. void rexxsetchat(struct RexxMsg *msg, char *p)
  1075.   {
  1076.   Do_Stack_Check();
  1077.   parseargs(p, 1) ;
  1078.   cfg.BoolFlags.noChat = (args[0]) ? FALSE : TRUE;
  1079.   ScrNewUser();
  1080.  
  1081.   }
  1082. void rexxsetecho(struct RexxMsg *msg, char *p)
  1083.   {
  1084.   Do_Stack_Check();
  1085.   parseargs(p, 1) ;
  1086.   anyEcho = (args[0]) ? TRUE : FALSE;
  1087.   ScrNewUser();
  1088.  
  1089.   }
  1090. void rexxsetnud(struct RexxMsg *msg, char *p)
  1091.   {
  1092.   Do_Stack_Check();
  1093.   parseargs(p, 1) ;
  1094.   CallSysop = (args[0]) ? TRUE : FALSE;
  1095.   ScrNewUser();
  1096.  
  1097.   }
  1098. extern char haveCarrier;
  1099. char retstr[4];
  1100. void rexxexit(struct RexxMsg *msg, char *p)
  1101.   {
  1102.   Do_Stack_Check();
  1103.   parseargs(p, 1) ;
  1104.   strcpy(retstr,"0");
  1105.   if (!haveCarrier || args[0] != 0)
  1106.     {
  1107.     ExitToMsdos = TRUE;
  1108.     exitValue = 0;
  1109.     strcpy(retstr,"1");
  1110.  
  1111.     }
  1112.   userreplied = 1;
  1113.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1114.  
  1115.   }
  1116. void rexxversion(struct RexxMsg *msg, char *p)
  1117.   {
  1118.   Do_Stack_Check();
  1119.   userreplied = 1 ;
  1120.   replyRexxCmd(msg, 0L, 0L, VERSION) ;
  1121.  
  1122.   }
  1123. void rexxserialenable(struct RexxMsg *msg, char *p)
  1124.   {
  1125.   Do_Stack_Check();
  1126.   parseargs(p, 2) ;
  1127.   strcpy(retstr,"0");
  1128.   if (!haveCarrier || args[1] != 0)
  1129.     {
  1130.     if (args[0])
  1131.       {
  1132.       SerialOpen = OpenSerial(FALSE);
  1133.       if (SerialOpen == TRUE) strcpy(retstr,"1");
  1134.  
  1135.       }
  1136.     else
  1137.       {
  1138.       SerialOpen = CloseSerial(FALSE);
  1139.       if (!SerialOpen) strcpy(retstr,"1");
  1140.  
  1141.       }
  1142.  
  1143.     }
  1144.   userreplied = 1;
  1145.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1146.  
  1147.   }
  1148. void rexxopenconsole(struct RexxMsg *msg, char *p)
  1149.   {
  1150.   Do_Stack_Check();
  1151.   parseargs(p, 1) ;
  1152.   strcpy(retstr,"0");
  1153.   if (args[0])
  1154.     {
  1155.     if (!ConOpen)
  1156.       {
  1157.       OpenConsoleStuff();
  1158.       iconify_window = FALSE;
  1159.       };
  1160.     }
  1161.   else
  1162.     {
  1163.     if (ConOpen)
  1164.       {
  1165.       if (whichIO == MODEM)
  1166.         {
  1167.         CloseConsoleStuff();
  1168.         iconify_window = TRUE;
  1169.         };
  1170.       };
  1171.     };
  1172.   if (ConOpen)
  1173.   strcpy(retstr,"1");
  1174.   else
  1175.   strcpy(retstr,"0");
  1176.   userreplied = 1;
  1177.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1178.  
  1179.   }
  1180. void rexxiconify(struct RexxMsg *msg, char *p)
  1181.   {
  1182.   int error;
  1183.   Do_Stack_Check();
  1184.   parseargs(p, 1) ;
  1185.   strcpy(retstr,"0");
  1186.   if (args[0])
  1187.     {
  1188.     if (ConOpen)
  1189.       {
  1190.       if (whichIO == MODEM)
  1191.         {
  1192.         error = OpenLittleWindow();
  1193.         if (error == TRUE)
  1194.           {
  1195.           CloseConsoleStuff();
  1196.           strcpy(retstr,"1");
  1197.           iconify_window = TRUE;
  1198.           }
  1199.  
  1200.         }
  1201.  
  1202.       }
  1203.  
  1204.     }
  1205.   else
  1206.     {
  1207.     if (!ConOpen)
  1208.       {
  1209.       error = OpenConsoleStuff();
  1210.       if (error > 0)
  1211.         {
  1212.         strcpy(retstr,"1");
  1213.         if (LittleWindow != NULL)
  1214.         CloseLittleWindow();
  1215.         iconify_window = FALSE;
  1216.  
  1217.         }
  1218.  
  1219.       }
  1220.  
  1221.     }
  1222.  
  1223.   userreplied = 1;
  1224.   replyRexxCmd(msg, 0L, 0L, retstr) ;
  1225.  
  1226.   }
  1227. #ifdef HANDLE_FALSE_CARRIER
  1228. void rexxcarrier(struct RexxMsg *msg, char *p)
  1229.   {
  1230.   Do_Stack_Check();
  1231.   parseargs(p, 1) ;
  1232.   FalseCarrier = (args[0]) ? TRUE : FALSE;
  1233.  
  1234.   }
  1235. #endif
  1236. #endif
  1237. int Handle_Window_Msg(struct IntuiMessage *InMsg)
  1238.   {
  1239.   ULONG msgclass;
  1240.   int err;
  1241.   Do_Stack_Check();
  1242.   msgclass = InMsg->Class;
  1243.   ReplyMsg((struct Message *)InMsg);
  1244.   if (msgclass == CLOSEWINDOW)
  1245.     {
  1246.     if (whichIO == MODEM)
  1247.       {
  1248.       err = OpenLittleWindow();
  1249.       if (err == FALSE)
  1250.         {
  1251.         DisplayBeep(NULL);
  1252.  
  1253.         }
  1254.       else
  1255.         {
  1256.         CloseConsoleStuff();
  1257.  
  1258.         }
  1259.  
  1260.       }
  1261.  
  1262.     }
  1263.   return(TRUE);
  1264.  
  1265.   }
  1266. int Handle_Little_Window_Msg(struct IntuiMessage *InMsg)
  1267.   {
  1268.   int err;
  1269.   Do_Stack_Check();
  1270.   ReplyMsg((struct Message *)InMsg);
  1271.   err = OpenConsoleStuff();
  1272.   if (err < 1)
  1273.     {
  1274.     DisplayBeep(NULL);
  1275.  
  1276.     }
  1277.   else
  1278.     {
  1279.     CloseLittleWindow();
  1280.  
  1281.     }
  1282.   return(TRUE);
  1283.  
  1284.   }
  1285. struct NewWindow NewLittleWindow =
  1286.   {
  1287.   100,0,188,12,(UBYTE)-1,(UBYTE)-1,
  1288.   CLOSEWINDOW,
  1289.   WINDOWDEPTH | WINDOWCLOSE | WINDOWDRAG | SMART_REFRESH | RMBTRAP,
  1290.   NULL, NULL,
  1291.   (UBYTE *)"Amiga Citadel",
  1292.   NULL,NULL,0,0,1000,1000,WBENCHSCREEN
  1293.  
  1294.   };
  1295. int OpenLittleWindow(void)
  1296.   {
  1297.   Do_Stack_Check();
  1298.   if (LittleWindow == NULL)
  1299.     {
  1300.     LittleWindow = OpenWindow(&NewLittleWindow);
  1301.  
  1302.     }
  1303.   if (LittleWindow != NULL)
  1304.   return(1);
  1305.   return(0);
  1306.  
  1307.   }
  1308. int CloseLittleWindow(void)
  1309.   {
  1310.   Do_Stack_Check();
  1311.   if (LittleWindow != NULL)
  1312.     {
  1313.     CloseWindow(LittleWindow);
  1314.     LittleWindow = NULL;
  1315.     return(1);
  1316.  
  1317.     }
  1318.   else return(0);
  1319.  
  1320.   }
  1321.  
  1322. int Jsystem(char *cmdline)
  1323.   {
  1324.   long ecode;
  1325.   char dir[80];
  1326.   BPTR nilfh;
  1327.   Do_Stack_Check();
  1328.   if (cfg.BoolFlags.debug)
  1329.     {
  1330.     (void)getcd(0,dir);
  1331.     splitF(NULL, " Dir:%s\n Command:%s\n",dir,cmdline);
  1332.     };
  1333.   (void)SetIoErr(0);       /* initialize the error code */
  1334.   pause(1);
  1335.   nilfh = Open("NIL:",MODE_OLDFILE);
  1336.   Execute(cmdline,NULL,nilfh);  /* execute the command */
  1337.   ecode = IoErr();          /* check for error */
  1338.   if( ecode != 0 )Dos_Error(ecode,cmdline);
  1339.   return((int)ecode);
  1340.   }
  1341.  
  1342. void Dos_Error(err,str)   /* format a AmigaDos Error and put in debug.sys */
  1343. long err;
  1344. char *str;
  1345.   {
  1346.   char *mon;
  1347.   int yr,day,hour,min;
  1348.   char buf[80];
  1349.   char CLogFn[80];            /* buffer for calllog.sys */
  1350.   Do_Stack_Check();
  1351.   if( cfg.Audit == 0)return;  /* exit if the Sysop has not configed Auditing*/
  1352.   makeAuditName(CLogFn, "debug.sys");
  1353.   getCdate(&yr,&mon,&day,&hour,&min);
  1354.   sprintf(buf,"%2d%s%02d %d:%02d - Dos Error:%ld",yr,mon,day,hour,min,err);
  1355.   CallMsg(CLogFn,buf);        /* time and date of the error */
  1356.   sprintf(buf,"%s",str);
  1357.   CallMsg(CLogFn, buf);       /* report the command */
  1358.   (void)Fault(err,"Reason:",buf,80);
  1359.   CallMsg(CLogFn, buf);       /* report the error in text */
  1360.   (void)getcd(0,buf);
  1361.   CallMsg(CLogFn, buf);       /* report the current directory */
  1362.   pause(3);
  1363.   }
  1364.  
  1365. void ReActivate_Window()
  1366.   {
  1367.   Do_Stack_Check();
  1368.   if( !ConOpen ) OpenConsoleStuff();/* reactivate window if closed */
  1369.   ScreenToFront(myWindow->WScreen); /* make sure that the screen is front */
  1370.   WindowToFront(myWindow);          /* make sure the window is in front */
  1371.   ActivateWindow(myWindow);         /* activate, it can't hurt */
  1372.   }
  1373.  
  1374. int QueueRead(struct IOStdReq *request,char *whereto)
  1375.   {
  1376.   Do_Stack_Check();
  1377.   if (ConOpen && !conqueued)
  1378.     {
  1379.     consoleReadMsg->io_Command = CMD_READ;
  1380.     consoleReadMsg->io_Data = (APTR)&conletter;
  1381.     consoleReadMsg->io_Length = 1;
  1382.     SendIO((struct IORequest *)consoleReadMsg);
  1383.     conqueued = TRUE;
  1384.  
  1385.     }
  1386.   return(TRUE);
  1387.  
  1388.   }
  1389. int UnQueueRead(void)
  1390.   {
  1391.   Do_Stack_Check();
  1392.   if (conqueued && ConOpen)
  1393.     {
  1394.     AbortIO((struct IORequest *)consoleReadMsg);
  1395.     WaitPort(consoleReadPort);
  1396.     MyGetMsg(consoleReadPort);
  1397.     conqueued = FALSE;
  1398.  
  1399.     }
  1400.   return(TRUE);
  1401.  
  1402.   }
  1403. int ConPutStr(char *myString)
  1404.   {
  1405.   Do_Stack_Check();
  1406.   if (!ConOpen || !myString || !strlen(myString))  return(0);
  1407.   consoleWriteMsg->io_Command = CMD_WRITE;
  1408.   consoleWriteMsg->io_Data = (APTR)myString;
  1409.   consoleWriteMsg->io_Length = strlen(myString);
  1410.   DoIO((struct IORequest *)consoleWriteMsg);
  1411.   return(1);
  1412.  
  1413.   }
  1414. int BufferConsoleFlush(void)
  1415.   {
  1416.   Do_Stack_Check();
  1417.   if (ConOpen && BufferConsoleCount)
  1418.     {
  1419.     consoleWriteMsg->io_Data = (APTR)ConsoleBuffer;
  1420.     consoleWriteMsg->io_Length = BufferConsoleCount;
  1421.     consoleWriteMsg->io_Command = CMD_WRITE;
  1422.     DoIO((struct IORequest *)consoleWriteMsg);
  1423.  
  1424.     }
  1425.   BufferConsoleCount = 0;
  1426.   return(TRUE);
  1427.  
  1428.   }
  1429. int ConPutChar(char myChar)
  1430.   {
  1431.   Do_Stack_Check();
  1432.   if (DoBufferConsole)
  1433.     {
  1434.     ConsoleBuffer[BufferConsoleCount++] = myChar;
  1435.     if(BufferConsoleCount > 126)
  1436.       {
  1437.       BufferConsoleFlush();
  1438.  
  1439.       }
  1440.  
  1441.     }
  1442.   else
  1443.     {
  1444.     if (ConOpen)
  1445.       {
  1446.       consoleWriteMsg->io_Command = CMD_WRITE;
  1447.       consoleWriteMsg->io_Data = (APTR)&myChar;
  1448.       consoleWriteMsg->io_Length = 1;
  1449.       DoIO((struct IORequest *)consoleWriteMsg);
  1450.  
  1451.       }
  1452.  
  1453.     }
  1454.   return(TRUE);
  1455.  
  1456.   }
  1457. int OpenConsoleStuff(void)
  1458.   {
  1459.   UWORD tmpcolors[2];
  1460.   int error,erred;
  1461.   Do_Stack_Check();
  1462.   if (ConOpen)  return(1);
  1463.   erred = 0;
  1464.   if (!WBWindow)
  1465.     {
  1466.     myNewScreen.Width     = cfg.DepData.ScreenWidth;
  1467.     myNewScreen.Height    = cfg.DepData.ScreenHeight;
  1468.     myNewScreen.Depth     = 1;  /* 3;   /* 8 colors */
  1469.     if (cfg.DepData.ScreenHeight > 399) myNewScreen.ViewModes |= LACE;
  1470.     sPrintf(NewScreenTitle,"Amiga Citadel V%s.%s",VERSION,SysVers);
  1471.     myNewScreen.DefaultTitle = (UBYTE *)NewScreenTitle;
  1472.     myScreen = (struct Screen *)OpenScreen(&myNewScreen);
  1473.     if (!myScreen) return(-1);
  1474.     myNewWindow.Screen = myScreen;
  1475.     myScreensRPort = &(myScreen->RastPort);
  1476.     myScreensBLine = myScreensRPort->Font->tf_Baseline + 1;
  1477.  
  1478.     }
  1479.   else
  1480.     {
  1481.     myNewWindow.Type    = WBENCHSCREEN;
  1482.     myNewWindow.Screen  = NULL;
  1483.     myScreensRPort      = NULL;
  1484.     myNewWindow.TopEdge = 0;
  1485.  
  1486.     }
  1487.   strcpy(NewWindowTitle,"Citadel Console");
  1488.   myNewWindow.Title = (UBYTE *)NewWindowTitle;
  1489.   myNewWindow.Width = cfg.DepData.ScreenWidth;
  1490.   if (!WBWindow)
  1491.     {
  1492.     myNewWindow.Height     = cfg.DepData.ScreenHeight - 10;
  1493.     myNewWindow.Flags     &= ~(WINDOWSIZING | WINDOWDRAG);
  1494.  
  1495.     }
  1496.   else  myNewWindow.Height = cfg.DepData.ScreenHeight;
  1497.   myWindow                 = OpenWindow(&myNewWindow);
  1498.   if (!myWindow)
  1499.     {
  1500.     if(myScreen)
  1501.       {
  1502.       CloseScreen(myScreen);
  1503.       myScreen = NULL;
  1504.  
  1505.       }
  1506.     return(-2);
  1507.  
  1508.     };
  1509.   if (myScreen)
  1510.     {
  1511.     tmpcolors[0] = cfg.DepData.Color0;
  1512.     tmpcolors[1] = cfg.DepData.Color1;
  1513.     LoadRGB4(ViewPortAddress(myWindow),tmpcolors,2);
  1514.     ((struct Process *)FindTask(0))->pr_WindowPtr = (APTR)myWindow;
  1515.  
  1516.     };
  1517.   consoleReadPort = CreatePort(0,0);
  1518.   if (!consoleReadPort)
  1519.     {
  1520.     erred = 3;
  1521.  
  1522.     }
  1523.   if (!erred)
  1524.     {
  1525.     consoleReadMsg = (struct IOStdReq *)CreateExtIO(consoleReadPort, sizeof(struct IOStdReq));
  1526.     if (!consoleReadMsg)
  1527.       {
  1528.       erred = 4;
  1529.  
  1530.       }
  1531.  
  1532.     }
  1533.   if (!erred)
  1534.     {
  1535.     consoleWritePort = CreatePort(0,0);
  1536.     if (!consoleWritePort)
  1537.       {
  1538.       erred = 5;
  1539.  
  1540.       }
  1541.  
  1542.     }
  1543.   if (!erred)
  1544.     {
  1545.     consoleWriteMsg = (struct IOStdReq *)CreateExtIO(consoleWritePort, sizeof(struct IOStdReq));
  1546.     if (!consoleWriteMsg)
  1547.       {
  1548.       erred = 6;
  1549.  
  1550.       }
  1551.  
  1552.     }
  1553.   if (!erred)
  1554.     {
  1555.     consoleReadMsg->io_Data = (APTR)myWindow;
  1556.     consoleReadMsg->io_Length = sizeof(struct Window);
  1557.     error = OpenDevice("console.device",0,(struct IORequest *)consoleReadMsg,0);
  1558.     if (error)
  1559.       {
  1560.       erred = 7;
  1561.  
  1562.       }
  1563.  
  1564.     }
  1565.   if (!erred)
  1566.     {
  1567.     consoleWriteMsg->io_Data = (APTR)myWindow;
  1568.     consoleWriteMsg->io_Length = sizeof(struct Window);
  1569.     consoleWriteMsg->io_Device = consoleReadMsg->io_Device;
  1570.     consoleWriteMsg->io_Unit = consoleReadMsg->io_Unit;
  1571.     ConOpen = TRUE;
  1572.     printf("Console opened: Columns = %d, Rows = %d\n ",
  1573.     myNewWindow.Width / myWindow->RPort->TxWidth, (myNewWindow.Height - myWindow->RPort->TxHeight - 2) / myWindow->RPort->TxHeight);
  1574.     QueueRead(consoleReadMsg,&conletter);
  1575.  
  1576.     }
  1577.   ReActivate_Window();
  1578.   if (erred)
  1579.     {
  1580.     CloseConsoleStuff();
  1581.  
  1582.     }
  1583.   return(0-erred);
  1584.  
  1585.   }
  1586. int CloseConsoleStuff(void)
  1587.   {
  1588.   Do_Stack_Check();
  1589.   UnQueueRead();
  1590.   if (ConOpen)  CloseDevice((struct IORequest *)consoleReadMsg);
  1591.   ConOpen = FALSE;
  1592.   if (consoleWriteMsg)
  1593.     {
  1594.     DeleteExtIO((struct IORequest *)consoleWriteMsg);
  1595.     consoleWriteMsg = NULL;
  1596.  
  1597.     }
  1598.   if (consoleWritePort)
  1599.     {
  1600.     DeletePort(consoleWritePort);
  1601.     consoleWritePort = NULL;
  1602.  
  1603.     }
  1604.   if (consoleReadMsg)
  1605.     {
  1606.     DeleteExtIO((struct IORequest *)consoleReadMsg);
  1607.     consoleReadMsg = NULL;
  1608.  
  1609.     }
  1610.   if (consoleReadPort)
  1611.     {
  1612.     DeletePort(consoleReadPort);
  1613.     consoleReadPort = NULL;
  1614.  
  1615.     }
  1616.   if (myWindow)
  1617.     {
  1618.     if (((struct Process *)FindTask(0))->pr_WindowPtr == myWindow)
  1619.     ((struct Process *)FindTask(0))->pr_WindowPtr = (APTR)NULL;
  1620.     CloseWindow(myWindow);
  1621.     myWindow = NULL;
  1622.  
  1623.     }
  1624.   if (myScreen)
  1625.     {
  1626.     CloseScreen(myScreen);
  1627.     myScreen = NULL;
  1628.  
  1629.     }
  1630.   return(TRUE);
  1631.  
  1632.   }
  1633. struct Message *MyGetMsg(struct MsgPort *MyMsgPort)
  1634.   {
  1635.   struct Message *RepliedMessage;
  1636.   Do_Stack_Check();
  1637.   if (RepliedMessage = GetMsg(MyMsgPort))
  1638.     {
  1639.     SetSignal(0L,(1L << MyMsgPort->mp_SigBit));
  1640.  
  1641.     }
  1642.   return(RepliedMessage);
  1643.  
  1644.   }
  1645. int SysdepCheckArg(char *arg)
  1646.   {
  1647.   Do_Stack_Check();
  1648.   return(0);
  1649.  
  1650.   }
  1651. /*
  1652.  * CitSystem()
  1653.  *
  1654.  * This function formats the format & arguments and then runs the result via
  1655.  * system().
  1656.  */
  1657. int CitSystem(char RestoreVideo, char *format, ...)
  1658. {
  1659.     va_list argptr;
  1660.     char *garp;
  1661.     extern char *bigbuffer;
  1662.     Do_Stack_Check();
  1663.     garp = bigbuffer;
  1664.     va_start(argptr, format);
  1665.     vsprintf(garp, format, argptr);
  1666.     va_end(argptr);
  1667. /*    if (RestoreVideo) StopVideo();  */
  1668.     Jsystem(garp);
  1669. /*    if (RestoreVideo) VideoInit();  */
  1670.     return 0;
  1671. }
  1672. unsigned long S_min = 0xFFFFFFFF;  /* min value seen */
  1673. unsigned long S_max = 0x00000000;  /* max value seen */
  1674. void Do_Stack_Check()
  1675.   {
  1676.   unsigned long S_current;
  1677.   S_current = getreg(REG_A7);  /* grab current stack pointer */
  1678.   if( S_current < S_min )S_min = S_current;
  1679.   if( S_current > S_max )S_max = S_current;
  1680.   }
  1681. /*
  1682. ** functions for caller count and user privledges
  1683. */
  1684. char logcall[100];
  1685. long Get_Call_Count()
  1686.   {
  1687.   FILE *ip;
  1688.   long count=0;
  1689.   if( cfg.Audit == 0)return 0;  /* exit if the Sysop has not configed Auditing*/
  1690.   makeAuditName(logcall, "user_count.sys");
  1691.   if( (ip = fopen(logcall,"r")) != NULL)
  1692.     {
  1693.     fread(&count,4,1,ip);
  1694.     fclose(ip);
  1695.     };
  1696.   return count;
  1697.   }
  1698.  
  1699. void Update_Caller_Count()
  1700.   {
  1701.   FILE *ip;
  1702.   long count=0;
  1703.   if( cfg.Audit == 0 ) return; /* Audit Area not setup */
  1704.   makeAuditName(logcall, "user_count.sys");
  1705.   if( (ip = fopen(logcall,"rb")) != NULL)
  1706.     {
  1707.     fread(&count,4,1,ip);
  1708.     fclose(ip);
  1709.     };
  1710.   if( (ip = fopen(logcall,"wb")) != NULL)
  1711.     {
  1712.     fseek(ip,0,SEEK_SET);
  1713.     count++;
  1714.     fwrite(&count,4,1,ip);
  1715.     fclose(ip);
  1716.     };
  1717.   }
  1718.  
  1719. char *Display_Privledges()
  1720.   {
  1721.   extern char      loggedIn;  /* Are we logged in?       */
  1722.   int count=0;                /* check for no privileges */
  1723.   logcall[0] = '\0';          /* initialize string       */
  1724.   if( loggedIn )
  1725.     {
  1726.     if (logBuf.lbflags.AIDE)
  1727.       {
  1728.       count++;
  1729.       strcat(logcall,"Aide, ");
  1730.       };
  1731.  
  1732.     if (logBuf.lbflags.NET_PRIVS)
  1733.       {
  1734.       count++;
  1735.       strcat(logcall,"NET, ");
  1736.       };
  1737.  
  1738.     if (logBuf.lbflags.DOOR_PRIVS)
  1739.       {
  1740.       count++;
  1741.       strcat(logcall,"Door, ");
  1742.       };
  1743.  
  1744.     if (logBuf.lbflags.DL_PRIVS)
  1745.       {
  1746.       count++;
  1747.       strcat(logcall,"File, ");
  1748.       };
  1749.  
  1750.     if (logBuf.lbflags.PERMANENT)
  1751.       {
  1752.       count++;
  1753.       strcat(logcall,"Permanent, ");
  1754.       };
  1755.  
  1756.     if (logBuf.lbflags.TWIT)
  1757.       {
  1758.       count++;
  1759.       logcall[0]='\0';
  1760.       strcat(logcall,"Full ");
  1761.       };
  1762.     };
  1763.   if( count == 0)strcpy( logcall, " No ");
  1764.   count = strlen(logcall);
  1765.   if( logcall[count-2] == ',')logcall[count-2] = '\0';
  1766.   return &logcall[0];
  1767.   }
  1768. /*
  1769. void Debug_space()
  1770.   {
  1771.   short i;
  1772.   for(i=0;i<level;i++)splitF(netLog," ");
  1773.   }
  1774. void Debug_Message(struct Message *Msg)
  1775.   {
  1776.   level++;
  1777.   Debug_space();splitF(netLog," struct Message:%08lX\n",Msg);
  1778.   level--;
  1779.   }
  1780. void Debug_Device( struct Device *Dev)
  1781.   {
  1782.   level++;
  1783.   Debug_space();splitF(netLog," struct Device:%08lX\n",Dev);  level--;
  1784.   }
  1785. void Debug_Unit(   struct Unit *Un)
  1786.   {
  1787.   level++;
  1788.   Debug_space();splitF(netLog," struct Unit :%08lX\n",Un);  level--;
  1789.   level--;
  1790.   }
  1791. int debug_count=0;
  1792. void DebugIoStdReq(struct IOStdReq *Std)
  1793.   {
  1794.   Debug_space();splitF(netLog,"struct IOStdReq:%08lX\n",Std);
  1795.   level++;
  1796.   Debug_Message(&Std->io_Message);
  1797.   Debug_Device( Std->io_Device);
  1798.   Debug_Unit(   Std->io_Unit);
  1799.   Debug_space();splitF(netLog,"io_Command:%04X\n",Std->io_Command);
  1800.   Debug_space();splitF(netLog,"  io_Flags:%02X\n",Std->io_Flags);
  1801.   Debug_space();splitF(netLog,"  io_Error:%02X\n",Std->io_Error);
  1802.   Debug_space();splitF(netLog," io_Actual:%08lX\n",Std->io_Actual);
  1803.   Debug_space();splitF(netLog," io_Length:%08lX\n",Std->io_Length);
  1804.   Debug_space();splitF(netLog,"   io_Data:%08lX\n",Std->io_Data);
  1805.   Debug_space();splitF(netLog," io_Offset:%08lX\n",Std->io_Offset);
  1806.   level--;
  1807.   }
  1808. void  DebugIoRequest (char * string,struct IOExtSer *iorequest)
  1809.   {
  1810.         int  mask = iorequest->io_SerFlags;
  1811.   if (!cfg.BoolFlags.debug)return;
  1812.   if( (debug_count++ % 1000 ) != 0 )return;
  1813.   Debug_space();splitF(netLog," %s=struct IOExtSer:%08lX\n",string,iorequest);
  1814.   DebugIoStdReq(&iorequest->IOSer);
  1815.   Debug_space();splitF(netLog,"CtlChar    0x%lx \n", iorequest->io_CtlChar);
  1816.   Debug_space();splitF(netLog,"RBufLen    %ld   \n", iorequest->io_RBufLen);
  1817.   Debug_space();splitF(netLog,"ExtFlags   0x%lx \n", iorequest->io_ExtFlags);
  1818.   Debug_space();splitF(netLog,"Baud       %ld   \n", iorequest->io_Baud);
  1819.   Debug_space();splitF(netLog,"BrkTime    %ld   \n", iorequest->io_BrkTime);
  1820.   Debug_space();splitF(netLog,"ReadLen    %ld   \n", iorequest->io_ReadLen);
  1821.   Debug_space();splitF(netLog,"WriteLen   %ld   \n", iorequest->io_WriteLen);
  1822.   Debug_space();splitF(netLog,"StopBits   %ld   \n", iorequest->io_StopBits);
  1823.   Debug_space();splitF(netLog,"SerFlags   0x%lx \n", iorequest->io_SerFlags);
  1824.         if (mask)
  1825.           {
  1826.     Debug_space();splitF(netLog,"           ");
  1827.                 if (mask & SERF_XDISABLED)  Debug_space();splitF(netLog,"XDISABLED ");
  1828.                 if (mask & SERF_EOFMODE)    Debug_space();splitF(netLog,"EOFMODE ");
  1829.                 if (mask & SERF_SHARED)     Debug_space();splitF(netLog,"SHARED ");
  1830.                 if (mask & SERF_RAD_BOOGIE) Debug_space();splitF(netLog,"RAD_BOOGIE ");
  1831.                 if (mask & SERF_QUEUEDBRK)  Debug_space();splitF(netLog,"QUEUEDBRK ");
  1832.                 if (mask & SERF_7WIRE)      Debug_space();splitF(netLog,"7WIRE ");
  1833.                 if (mask & SERF_PARTY_ODD)  Debug_space();splitF(netLog,"PARTY_ODD ");
  1834.                 if (mask & SERF_PARTY_ON)   Debug_space();splitF(netLog,"PARTY_ON");
  1835.     Debug_space();splitF(netLog,"\n");
  1836.           }
  1837.   Debug_space();splitF(netLog,"Status     0x%lx \n", iorequest->io_Status);
  1838.         return;
  1839. }
  1840. */
  1841.